<#assign content>
<div class="right_col" role="main">
    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h3>角色-菜单设置</h3>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2><small></small></h2>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <p class="text-muted font-13 m-b-30">
                                <button type="button" class="btn btn-success" id="btn-check-all">全选</button>
                                <button type="button" class="btn btn-danger" id="btn-uncheck-all">取消全选</button>
                            </p>
                            <div id="treeview-menu" class=""></div>
                            <div class="ln_solid"></div>
                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-5">
                                    <button id="save_roleamenu" type="button" class="btn btn-success">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</#assign>
<#include "../_inc/layout.ftl" />
<script src="/_comm/build/js/treeview.js"></script>
<script>

    <#if menuList?exists>
        var defaultData = ${menuList};
        $('#treeview-menu').treeview({
            data: defaultData,
            showIcon: false,
            showCheckbox: true,
            showTags: true,
            onNodeChecked: $.nodeChecked,
            onNodeUnchecked: $.nodeUnchecked
        });
    </#if>

    $('#save_roleamenu').on('click', function () {
        var menuValue = $('#treeview-menu').treeview('getChecked');
        var menuArray = [];
        if(menuValue != null && menuValue.length > 0) {
            $.each(menuValue, function (index, value) {
                menuArray.push(value.id);
            });
            var param = {};
            param.id = '${id}';
            param.action = 'roleSetMenu';
            param.menuValue = menuArray;
            $.ajax({
                type: 'POST',
                url: '/role_set_menu.do',
                cache: false,                                   //禁用缓存
                data: param,                                    //传入组装的参数
                dataType: 'json',
                traditional: true,
                success: function (result) {
                    if(result.success) {
                        location.reload();                      // 刷新
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        }
        else {
            $.promptModal('${warning}', '请选择菜单', false);
        }
    });


</script>